/*
 *  Utility.cpp
 *  SoundController0002
 *
 *  Created by jiro on 10/07/01.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#include "Utility.h"

namespace sc
{

	boost::minstd_rand* RandomValueGenerator::randomValueSeed;

	boost::uniform_real<>* RandomValueGenerator::distribution;

	boost::variate_generator< boost::minstd_rand&, boost::uniform_real<> >* RandomValueGenerator::generator;

	void RandomValueGenerator::Initialize( double seed, double minValue, double maxValue )
	{
		if ( randomValueSeed == NULL )
		{
			delete randomValueSeed;
			delete distribution;
			delete generator;
		}
		randomValueSeed = new boost::minstd_rand( seed );
		distribution = new boost::uniform_real<>( minValue, maxValue );
		generator = new boost::variate_generator< boost::minstd_rand&, boost::uniform_real<> >( * randomValueSeed, * distribution );
	}

	double RandomValueGenerator::GetValue( double minValue, double maxValue )
	{
		if ( distribution->min() != minValue or distribution->max() != maxValue )
		{
			Initialize( minValue + maxValue, minValue, maxValue );
		}
		return (*generator)();
	}

}
